package com.zhiyin.seal.controller;

import com.zhiyin.seal.entity.bo.NoticeBo;
import com.zhiyin.seal.entity.dto.AddNoticeDTO;
import com.zhiyin.seal.entity.dto.ResponseDTO;
import com.zhiyin.seal.entity.vo.NoticeVo;
import com.zhiyin.seal.service.NoticeService;
import com.zhiyin.seal.util.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公告业务控制器
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    NoticeService noticeService;

    @PostMapping("/publish")
    public ResponseDTO<Boolean> publishNotice(@RequestBody AddNoticeDTO noticeDTO) {
        return ResponseDTO.succData(noticeService.publishNotice(BeanUtil.copy(noticeDTO, NoticeBo.class)));
    }

    @GetMapping("/list")
    public ResponseDTO<List<NoticeVo>> getNoticeList(@RequestParam Long companyId){
        return ResponseDTO.succData(BeanUtil.copyList(noticeService.getNoticeList(companyId),NoticeVo.class));
    }

    @GetMapping("/detail")
    public ResponseDTO<NoticeVo> getNoticeDetail(@RequestParam Long id){
        return ResponseDTO.succData(BeanUtil.copy(noticeService.getNoticeDetail(id),NoticeVo.class));
    }

    @PutMapping("/modify")
    public ResponseDTO<Boolean> modifyNotice(@RequestBody AddNoticeDTO noticeDTO){
        return ResponseDTO.succData(noticeService.modifyNotice(BeanUtil.copy(noticeDTO,NoticeBo.class)));
    }

    @DeleteMapping("/delete")
    public ResponseDTO<Boolean> deleteNotice(@RequestParam Long id){
        return ResponseDTO.succData(noticeService.deleteNotice(id));
    }

    @PutMapping("/update/display")
    public ResponseDTO<Boolean> updateDisplay(@RequestBody AddNoticeDTO noticeDTO){
        return ResponseDTO.succData(noticeService.updateDisplay(BeanUtil.copy(noticeDTO,NoticeBo.class)));
    }
}
